翻訳と辞書
Words near each other
・ Type K
・ Type L submarine
・ Type locality
・ Type locality (geology)
・ Type M
・ Type metal
・ Type Museum
・ Type N3 ship
・ Type O Negative
・ Type O Negative discography
・ Type of Constans
・ Type of service
・ Type of Way
・ Type P3 ship
・ Type physicalism
Type punning
・ Type qualifier
・ Type rating
・ Type RO 15
・ Type rule
・ Type S
・ Type safety
・ Type Sage
・ Type scene
・ Type set
・ Type signature
・ Type site
・ Type species
・ Type specimen (mineralogy)
・ Type system


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

Type punning : ウィキペディア英語版
Type punning

In computer science, type punning is a common term for any programming technique that subverts or circumvents the type system of a programming language in order to achieve an effect that would be difficult or impossible to achieve within the bounds of the formal language.
In C and C++, constructs such as type conversion and union — C++ adds reinterpret_cast to this list — are provided in order to permit many kinds of ''type punning'', although some kinds are not actually supported by the standard language.
In the Pascal programming language, the use of records with variants may be used to treat a particular data type in more than one manner, or in a manner not normally permitted.
== Sockets example ==
One classic example of ''type punning'' is found in the Berkeley sockets interface. The function to bind an opened but uninitialized socket to an IP address is declared as follows:

int bind(int sockfd, struct sockaddr
*my_addr, socklen_t addrlen);

The bind function is usually called as follows:

struct sockaddr_in sa = ;
int sockfd = ...;
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
bind(sockfd, (struct sockaddr
*)&sa, sizeof sa);

The Berkeley sockets library fundamentally relies on the fact that in C, a pointer to struct sockaddr_in is freely convertible to a pointer to struct sockaddr; and, in addition, that the two structure types share the same memory layout. Therefore, a reference to the structure field my_addr->sin_family (where my_addr is of type struct sockaddr
*
) will actually refer to the field sa.sin_family (where sa is of type struct sockaddr_in). In other words, the sockets library uses ''type punning'' to implement a rudimentary form of inheritance.
Often seen in the programming world is the use of "padded" data structures to allow for the storage of different kinds of values in what is effectively the same storage space. This is often seen when two structures are used in mutual exclusivity for optimization.

抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「Type punning」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.